{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# of removed outlier points:  133 / 2000\n",
      "Nr. of extracted clusters 4\n",
      "Cluster #0,  N = 2000\n",
      "Cluster #1,  N = 2000\n",
      "Cluster #2,  N = 2000\n",
      "Cluster #3,  N = 1867\n",
      "Access individual clusters through attribute: actor.cluster\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c74b38f1c9f7465585c6210a615fabb9",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[4.5, 4.5, 4.5, 0.0, 0.0, 0.0, 1.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Example usage of removeOutliers()\n",
    "and cluster() methods.\n",
    "\"\"\"\n",
    "from vtkplotter import show, cluster, removeOutliers, Text\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "# generate 4 random sets of N points in space\n",
    "N = 2000\n",
    "f = 0.6\n",
    "noise1 = np.random.rand(N, 3) * f + np.array([1, 1, 0])\n",
    "noise2 = np.random.rand(N, 3) * f + np.array([1, 0, 1.2])\n",
    "noise3 = np.random.rand(N, 3) * f + np.array([0, 1, 1])\n",
    "noise4 = np.random.randn(N, 3)* f/8 + np.array([1, 1, 1])\n",
    "\n",
    "noise4 = removeOutliers(noise4, 0.05)\n",
    "\n",
    "# merge points to lose their identity\n",
    "pts = noise1.tolist() + noise2.tolist() + noise3.tolist() + noise4.tolist()\n",
    "\n",
    "# find back their identity through clustering\n",
    "cl = cluster(pts, radius=0.1)  # returns a vtkAssembly\n",
    "\n",
    "cl.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
